<?php $this->_extends('_layouts/default_layout'); ?>
 
<?php $this->_block('contents'); ?>

<span><h3>批量用户录入</h3></span>
<p><span class="error" name="tip">手机号码之间请用英文的','或者是'*'分开，批量录入用户的用户密码与手机号码相同</span></p>
<p><span class="tip" name="tip">例：15898769090, 15898769091,15898769098</span></p>

<form action="<?php echo url('user/batchadd'); ?>" method="post" name="mainform" enctype="multipart/form-data"
		>
	<table cellpadding="0" cellspacing="0" width="100%">
	<tbody class="">
	<tr>
		<td><textarea class="input" type="text" value="" rows="14" cols="65" onblur="SplitUserinfo()" name="userinfo" id="userinfo" size="36" ></textarea></td>
	</tr>
	
	<tr>
		<input type='hidden' name='submitted' value='TRUE' id='".time()."'>
		<td class="tbutton" colspan="6"><input type="submit" onclick="return(CheckFirst())" value="提交" class="btn" name="submit">&nbsp;</td>
	</tr>
	</tbody>
	</table>
</form>

<script language = "JavaScript">
	function IsTelephone(obj)// 正则判断
	{ 
	//检查是不是电话号码
		//var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/; 
		var regex = {     mobile: /^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/ } 

		if(regex.mobile.test(obj)) 
		{ 
			return true; 
		} 
		else 
		{ 
			return false; 
		} 
	} 
	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g, "");
	}

	function   SplitUserinfo()     //   两边空格 
	{   
		str=document.getElementById('userinfo').value;
		arr=str.split(","); //字符分割    
		if(arr.length == 0)
		{
			arr=str.split("*"); //字符分割    
		}
		if(arr.length == 0)
		{
			return 1;
		}
		var resultstr='';
		for(var i=0;i<arr.length;i++)
		{
			if(!IsTelephone(arr[i].trim()))
			{
				return 2;
			}
		}

		for(var i=0;i<arr.length;i++)
		{
			 //一种方法: 利用js将数组拆分,用text盛载;
			 document.mainform.innerHTML +="<input type=\"hidden\" name=\"MyBatchTelphone[]\" value=\""
                         +arr[i].trim()
                         +"\">";			 
		}

		//document.mainform.submit(); 

		//var url = "<?php echo url('user/DoBactchAdd'); ?>?userinfo=" + escape(newlist);
		//request.open("GET", url, true);
		//request.onreadystatechange = updatePage;
		//request.send(null);
		return true;
	}  

	function CheckFirst()
	{
		if(document.getElementById('userinfo').value == '')
		{
			alert("请输入用户手机号码信息");
		}
		var ret=0;
		str=document.getElementById('userinfo').value;
		arr=str.split(","); //字符分割    
		if(arr.length == 0)
		{
			arr=str.split("*"); //字符分割    
		}
		if(arr.length == 0)
		{
			ret=1;
		}
		var resultstr='';
		for(var i=0;i<arr.length;i++)
		{
			if(!IsTelephone(arr[i].trim()))
			{
				ret=2;
				break;
			}
		}

		if(1 == ret)
		{
			alert("请使用正确的分隔符分割");
		}
		else if(2 == ret)
		{
			alert("请确认您输入的是手机号码");
		}

		return true;
	}
</script>

<?php $this->_endblock(); ?>